package com.color.admin.common.core.utils.tools;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author HaiQiu
 * @date 2022/2/17
 */
public class PoiUtils {


    public static void main(String[] args) {
        Workbook wb = new HSSFWorkbook();
        Sheet sheet1 = wb.createSheet("sheet01");
        Sheet sheet2 = wb.createSheet("sheet02");

        CreationHelper creationHelper = wb.getCreationHelper();

        Row row = sheet1.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue(1);

        // Or do it on one line.
        row.createCell(1).setCellValue(1.2);
        row.createCell(2).setCellValue(
                creationHelper.createRichTextString("This is a string"));
        row.createCell(3).setCellValue(true);
        // Write the output to a file
        try (OutputStream fileOut = new FileOutputStream("D:\\Color_Files\\workbook.xls")) {
            wb.write(fileOut);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            wb.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
